package vo;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

import util.HibernateUtil;

public class SaidaDAO {

	public void salvar(SaidaVO vo) {

		Transaction transaction = null;

		Session session = HibernateUtil.currentSession();
		transaction = session.beginTransaction();

		session.saveOrUpdate(vo);

		transaction.commit();

	}


	@SuppressWarnings("unchecked")
	public List<SaidaVO> consultar(Date dataInicio, Date dataFim) {
		List<SaidaVO> lista = new ArrayList<SaidaVO>();
		Session session = HibernateUtil.currentSession();
		Transaction transaction = session.beginTransaction();
		Criteria criteria = session.createCriteria(SaidaVO.class);

		criteria.add(Restrictions.between("data", dataInicio, dataFim));

		lista = criteria.list();
		transaction.commit();

		return lista;
	}

	public void excluir(SaidaVO vo) {
		Transaction transaction = null;

		Session session = HibernateUtil.currentSession();
		transaction = session.beginTransaction();

		session.delete(vo);

		transaction.commit();
	}

}
